package com.tongguan.paypos.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.tongguan.paypos.R;
import com.tongguan.paypos.entity.Manage;

import java.util.ArrayList;

/**
 * Created by Joylive on 2016/12/14 .
 */

public class ManageAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<Manage> mDatas;

    public ManageAdapter(Context context, ArrayList<Manage> datas) {
        mContext = context;
        this.mDatas = datas;
    }

    @Override
    public int getCount() {
        if (mDatas != null && mDatas.size() > 0)
            return mDatas.size();
        else
            return 0;
    }

    @Override
    public Manage getItem(int position) {
        if (mDatas != null && mDatas.size() > 0)
            return mDatas.get(position);
        else
            return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_manage_gv, null);
            holder.mImageView = (ImageView) convertView.findViewById(R.id.iv_manage_item);
            holder.mTextView = (TextView) convertView.findViewById(R.id.tv_manage_item);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        Manage manage = mDatas.get(position);
        holder.mImageView.setImageResource(manage.getResId());
        holder.mTextView.setText(manage.getName());
        return convertView;
    }

    private class Holder {
        ImageView mImageView;
        TextView mTextView;
    }

}
